Calculates a serial time value from the specified hour, minute, and second - parameters passed as strings - that represents the time in a single numeric value. This value can be used to calculate the difference between times.
文字列として指定された時、分、秒の値を基に、該当する時刻を示す 1 つの数値 (シリアル値) を返します。こうして変換された数値は、2 つの時刻間の時間計算などに利用できます。
TimeValue (Text As String)
TimeValue (Text As String)
Date
日付
Text: Any string expression that contains the time that you want to calculate in the format "HH:MM:SS".
Text: 「HH:MM:SS」の形式で指定した、変換する時刻データを示す文字列表式。
Use the TimeValue function to convert any time into a single value, so that you can calculate time differences.
この関数は、任意の時刻を 1 つの数値として変換するもので、こうした得られる数値は時刻間の時間計算などに利用できます。
This TimeValue function returns the type Variant with VarType 7 (Date), and stores this value internally as a double-precision number between 0 and 0.9999999999.
この TimeValue 関数 の返す値は、バリアント型の VarType 7 (Date) であり、内部的には0から 0.9999999999 の倍精度値として格納されます。
As opposed to the DateSerial or the DateValue function, where serial date values result in days relative to a fixed date, you can calculate with the values that are returned by the TimeValue function, but you cannot evaluate them.
DateSerial や DateValue 関数では、日付データをシリアル値に変換する際に、固定設定された基準日からの経過日数として換算していますが、TimeValue 関数で返される値は、時刻間の計算には使えるものの、そのまま直接的な評価が行えるものではありません。
In the TimeSerial function, you can pass individual parameters (hour, minute, second) as separate numeric expressions. For the TimeValue function, however, you can pass a string as a parameter containing the time.
TimeSerial 関数の場合、関数に渡すパラメータ (時、分、秒) は、それぞれ個別の数値表式として指定することができます。これに対して TimeValue 関数では、時刻データを 1 つの文字列の形で渡します。
Sub ExampleTimerValue
Sub ExampleTimerValue
Dim daDT as Date
Dim daDT as Date
Dim a1, b1, c1, a2, b2, c2 as String
Dim a1, b1, c1, a2, b2, c2 as String
a1 = "start time"
a1 = "start time"
b1 = "end time"
b1 = "end time"
c1 = "total time"
c1 = "total time"
a2 = "8:34"
a2 = "8:34"
b2 = "18:12"
b2 = "18:12"
daDT = TimeValue(b2) - TimeValue(a2)
daDT = TimeValue(b2) - TimeValue(a2)
c2 = a1 & ": " & a2 & chr(13)
c2 = a1 & ":" & a2 & chr(13)
c2 = c2 & b1 & ": " & b2 & chr(13)
c2 = c2 & b1 & ":" & b2 & chr(13)
c2 = c2 & c1 & ": " & trim(Str(Hour(daDT))) & ":" & trim(Str(Minute(daDT))) & ":" & trim(Str(Second(daDT)))
c2 = c2 & c1 & ":" & trim(Str(Hour(daDT))) & ":"& trim(Str(Minute(daDT))) & ":"& trim(Str(Second(daDT)))
Msgbox c2
Msgbox c2
end sub
end sub